package com.shc.community.controller;


import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/ap")
public class demoController {
    @RequestMapping("hello")
    @ResponseBody
    public String demo(){
        return "hello!SpringBoot";
    }

    @RequestMapping(path = "/student",method = RequestMethod.POST)
    @ResponseBody
    public String getStudent(String name , int age){

        System.out.println(name + age);

        return "success";
    }

    @RequestMapping(path = "/teacher",method = RequestMethod.GET)
    public String findTeacher(Model model){
        model.addAttribute("name","张三");
        model.addAttribute("age",12);
        return "/demo/teacher";
    }

    @RequestMapping(path = "/json",method = RequestMethod.GET)
    @ResponseBody
    public List<Map<String,Object>> getJson(){
        ArrayList<Map<String,Object>> list = new ArrayList<>();
        Map<String, Object> m = new HashMap<>();
        m.put("name","张三");
        m.put("age",12);
        list.add(m);
        m = new HashMap<>();
        m.put("name","李四");
        m.put("age",15);
        list.add(m);
        return list;
    }
}
